<html><body><pre><script>
function sqrtIter(guess, x) {
    return goodEnough(guess, x) ? guess 
                                : sqrtIter(improve(guess, x), x);
}
function improve(guess, x) {
    return average(guess, x/guess);
}
function average(x, y) {
    return (x+y)/2;
}
function goodEnough(guess, x) {
    return (Math.abs(guess*guess-x) < 0.001);
}  
function sqrt(x) {
    return sqrtIter(1, x);
}

document.writeln(9, " ",sqrt(9));
document.writeln(2, " ",sqrt(2));
document.writeln(Math.PI, " ",sqrt(Math.PI));
document.writeln(12345654321, " ",sqrt(12345654321));
document.writeln(1234567654321, " ",sqrt(1234567654321));
</script></pre></body></html>

